<template>
  <div class="bidAnnouncement w1200">
    <supplier-display-header style="padding: 25px 20px;" title="最新中标" @more="toNotice"></supplier-display-header>
    <div class="result_box">
      <table class="result_table">
        <tr class="first">
          <td v-for="item in columns" :key="item.key" :width="item.width">
            {{ item.title }}
          </td>
        </tr>
        <tbody v-for="(a, index) in noticeScrollNum" :key="index" @mouseleave="toStartRunNotice"
          @mouseenter="toPausedRunNotice"
          :class="[noticeScrollNum > 1 ? 'result_table_scroll' : '', noticeAnimationPlayState]">
          <tr v-for="result in resultData" :key="result.id">
            <td v-for="item in columns" :key="result.id + item.key" :width="item.width" :style="item.style">
              <template v-if="item.key === 'operation'">
                <template v-if="isLogin">
                  <div class="operate" @click="toDetail(result.url)">查看标讯详情</div>
                  <!-- <div class="operate" style="margin-top: 6px;" @click="toSupplier(result.supplierCode)">
                    查看供应商</div> -->
                </template>
                <template v-else>
                  <div class="operate" @click="toLogin()">登录查看更多</div>
                </template>
              </template>
              <div v-else-if="item.key === 'bidAmount'"><span v-if="result[item.key]">¥{{ result[item.key]
              }}</span></div>
              <div v-else-if="item.key === 'bidTime'">{{ result[item.key] | datefmt }}</div>
              <div v-else-if="item.key === 'sectionName'" class="name" :title="result[item.key]">{{
                result[item.key] }}</div>
              <div v-else-if="item.key === 'purchaserName' || item.key === 'winnerName'">
                <template v-if="result[item.key] && result[item.key].length > 0">
                  <template v-if="isLogin">{{ result[item.key] }}</template>
                  <template v-else>{{ result[item.key][0] }}**</template>
                </template>
              </div>
              <template v-else>
                {{ result[item.key] }}
              </template>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>
  
<script>
import SupplierDisplayHeader from './SupplierDisplayHeader'
import storage from '@/utils/storage'
import { listPage } from '@/api/portal'

const columns = [
  {
    title: '项目名称',
    key: 'sectionName',
    width: '30%',
    style: {
      textAlign: 'left',
      paddingLeft: '20px',
      paddingRight: '20px',
    }
  },
  {
    title: '项目发布人',
    key: 'purchaserName',
    width: '15%'
  },
  {
    title: '中标人',
    key: 'winnerName',
    width: '12%'
  },
  {
    title: '中标金额',
    key: 'bidAmount',
    width: '14%'
  },
  {
    title: '中标时间',
    key: 'bidTime',
    width: '14%'
  },
  {
    title: '操作',
    key: 'operation',
    width: '15%'
  },
]
export default {
  name: 'Brand',
  components: {
    SupplierDisplayHeader
  },
  data() {
    return {
      columns,
      resultData: [],
      isLogin: storage.session.get('isLogin') && storage.session.get('authToken'),
      noticeAnimationPlayState: 'animationPlayStateRun',
      meetingAnimationPlayState: 'animationPlayStateRun',
      scrollWrapHeight: 406
    }
  },
  computed: {
    noticeScrollNum: function () {
      let scrollHeight = this.resultData.length * 60
      if (scrollHeight > this.scrollWrapHeight) {
        return 2
      } else {
        return 1
      }
    },
    meetingScrollNum: function () {
      let scrollHeight = this.meetingData.length * 79
      if (scrollHeight > this.scrollWrapHeight) {
        return 2
      } else {
        return 1
      }
    }
  },
  mounted() {
    this.loadData()
  },
  methods: {
    toLogin() {

    },
    loadData() {
      let params = {page:1,limit:20}
      listPage(params).then(res => {
        if(res.code == 0) {
          this.resultData = res.data.records || []
        }
      })
    },
    toNotice() {
      this.$router.push('/bidAnnouncementList')

    },
    toDetail(url) {
      if (url) {
        window.open(url, '_blank')
      } else {
        this.$message.info('暂无跳转链接')
      }
    },
    toPausedRunNotice() {
      this.noticeAnimationPlayState = "animationPlayStatePaused"
    },
    toStartRunNotice() {
      this.noticeAnimationPlayState = "animationPlayStateRun"
    },
    toPausedRunMeeting() {
      this.meetingAnimationPlayState = "animationPlayStatePaused"
    },
    toStartRunMeeting() {
      this.meetingAnimationPlayState = "animationPlayStateRun"
    }
    // })
    // },
  }
}
</script>
  
<style scoped lang="scss">
$mainColor: #3370FF;

.bidAnnouncement {
  background-color: #fff;
  height: 480px;
  overflow: hidden;
  box-shadow: 0px 4px 20px 0px rgba(0, 120, 254, 0.1);
  border-radius: 10px;
}

.result_box {
  flex: 1;
  overflow-y: hidden;
  //padding-bottom: 20px;

  &::-webkit-scrollbar {
    display: none;
  }
}

.result_table {
  width: 100%;
  color: #323232;
  font-weight: normal;

  .animationPlayStateRun {
    animation-play-state: running;
  }

  .animationPlayStatePaused {
    animation-play-state: paused;
  }


  &_scroll {
    animation: scrollNotice 30s infinite linear;
  }

  @keyframes scrollNotice {
    from {
      transform: translateY(0px);
    }

    to {
      transform: translateY(-100%);
    }
  }

  tr {
    //border-bottom: 1px dotted #e2e2e2;
    cursor: pointer;
    position: relative;

    &:after {
      content: '';
      border-bottom: 1px dotted $mainColor;
      left: 0;
      right: 0;
      position: absolute;
      bottom: 0;
    }

    &:hover {
      background: rgba(0, 120, 254, 0.1);
    }

    td {
      text-align: center;
      padding: 10px 0;
      font-family: PingFangSC-Regular, sans-serif;
      font-size: 14px;
      line-height: 14px;
    }

    &.first {
      background: #E5F1FF;
      border: none;
      position: sticky;
      top: 0;
      z-index: 99;

      &:after {
        display: none;
      }

      &:hover {
        background: #E5F1FF;
      }

      td {
        font-family: PingFang SC, sans-serif;
        font-size: 16px;
        padding: 0;
        line-height: 40px;
      }
    }
  }

  .operate {
    width: 90px;
    height: 22px;
    line-height: 20px;
    margin: auto;
    border-radius: 20px;
    border: 1px solid $mainColor;
    cursor: pointer;
    text-align: center;
    font-family: PingFangSC-Regular, sans-serif;
    font-size: 12px;
    color: $mainColor;
  }

  .name {
    word-break: break-all;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    transition: all linear 0.2s;
    cursor: pointer;
    line-height: 20px;
  }
}
</style>
  